package entity;

import java.util.List;

/**
 * Values and methods for specifying the SUMMARY property
 * for the iCalendar object as defined in RFFC 5545. This 
 * property defines a short summary or subject for the
 * calendar component.
 * 
 * @author Sean Young
 * @version 1.0
 *
 */
public class Summary {
	
	/** A string containing other parameters for the DTEND property. */
	private String otherparam;
	
	/** A string containing the alternate representation parameter */
	private String altrepparam;
	
	/** A string containing the language parameter*/
	private String languageparam;
	
	/** A string containing the summary of the event*/
	private String summary;
	
	/**
     * Constructor for the SUMMARY property. Fields are defaulted
     * to null.
     */
	public Summary() {
		this.otherparam = null;
		this.altrepparam = null;
		this.languageparam = null;
		this.summary = null;
	}
	
	/**
     * Constructor for the SUMMARY property. Sets the value of the 
     * SUMMARY property to the value specified in the parameter.
     * @param summary The summary of the event.
     */
	public Summary(String summary) {
		this.otherparam = null;
		this.altrepparam = null;
		this.languageparam = null;
		this.summary = summary;
	}
	
	/**
     * Sets the Alternate representation parameter for the
     * SUMMARY property
     * @param altrepparam The alternate representation parameter
     */
	public void setAltRepParam(String altrepparam) {
		this.altrepparam = altrepparam;
	}
	
	/**
     * Sets the Language parameter for the SUMMARY property
     * @param languageparam The alternate representation parameter
     */
	public void setLanguageParam(String languageparam) {
		this.languageparam = languageparam;
	}
	
	/**
	 * Sets the value of the "other" parameter field.
	 * @param otherparam The "other" parameter. Must be a single
	 *                   parameter.
	 */
	public void setOtherParam(String otherparam) {
		this.otherparam = otherparam;
	}
	
	/**
	 * Sets the value of the "Other" parameter field. 
	 * @param otherparams A List containing the parameters to be added
	 *                    to the "other" parameter.
	 */
	public void setOtherParam(List<String> otherparams) {
		StringBuilder parameterBuilder = new StringBuilder();
		for(int i = 0; i < otherparams.size(); i++) {
			parameterBuilder.append(otherparams.get(i));
			if((otherparams.size() != 1) && (i != otherparams.size() - 1)) parameterBuilder.append(";");
		}
		this.otherparam = parameterBuilder.toString();
	}
	
	/**
	 * Sets the summary to the specified text.
	 * @param summaryText The summary
	 */
	public void setSummary(String summaryText) {
		this.summary = summaryText;
	}
	
	/**
	 * Returns a string containing the values of the fields of the
	 * SUMMARY property. If no parameters were specified then they 
	 * will not be included. 
	 * 
	 * @return A string containing the properly formatted SUMMARY property.
	 */
	public String toString() {
		StringBuilder summaryString = new StringBuilder("SUMMARY");
		
		if(altrepparam != null) summaryString.append(altrepparam);
		if(languageparam != null) {
			if(altrepparam != null)summaryString.append(";");
			summaryString.append(languageparam);
		}
		if(otherparam != null) {
			if(altrepparam != null || languageparam != null) summaryString.append(";");
			summaryString.append(otherparam);
		}
		
		summaryString.append(":");
		
		summaryString.append(summary);
		summaryString.append("\r\n");
		
		return summaryString.toString();
	}
}
